import Vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Compression from 'vite-plugin-compression'
import SetupExtend from 'vite-plugin-vue-setup-extend'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'
import Components from 'unplugin-vue-components/vite'

export function createVitePlugins() {
    return [
        Vue(),
        ElementPlus({}),
        AutoImport({
             imports: [
                 'vue',
                 'vue-router',
                 'pinia'
             ],
            dts: 'src/types/auto-imports.d.ts',
            resolvers: [ElementPlusResolver()],
        }),
        Compression({
            verbose: true, // 是否在控制台输出压缩结果
            disable: false, // 是否禁用
            threshold: 10240, // 体积大于 threshold 才会被压缩,单位 b
            algorithm: 'gzip', // 压缩算法,可选 [ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw']
            ext: '.gz', // 生成的压缩包后缀
            deleteOriginFile: false //压缩后是否删除源文件
        }),
        SetupExtend(),
        Components({
            // 要搜索组件的目录的相对路径
            dirs: ['src/components'],
            // 组件的有效文件扩展名
            extensions: ['vue', 'md'],
            // 搜索子目录
            deep: true,
            include: [/\.vue$/, /\.vue\?vue/],
            // 生成自定义 `auto-components.d.ts` 全局声明
            dts: 'src/types/auto-components.d.ts',
            // 自定义组件的解析器
            resolvers: [ElementPlusResolver()],
            exclude: [/[\\/]node_modules[\\/]/]
        }),
    ]
}